package com.ruoyi.business.controller;

import com.ruoyi.business.dto.CardetailDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.Cardetail;
import com.ruoyi.business.service.ICardetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.Arrays;
import java.util.List;

/**
 * cardetailController
 *
 * @author liutietou
 * @since 1.0 2025-07-15
 */
@RestController
@RequestMapping("/business/cardetail")
public class CardetailController extends BaseController {
    @Autowired
    private ICardetailService cardetailService;

    /**
     * 查询cardetail列表
     */
    @PreAuthorize("@ss.hasPermi('business:cardetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(CardetailDto cardetail) {
        Page<CardetailDto> page = cardetailService.findCardetailPage(cardetail);
        return getDataTable(page);
    }

    /**
     * 导出cardetail列表
     */
    @PreAuthorize("@ss.hasPermi('business:cardetail:export')")
    @Log(title = "cardetail", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CardetailDto cardetail) {
        List<Cardetail> list = cardetailService.findCardetailList(cardetail);
        ExcelUtil<Cardetail> util = new ExcelUtil<>(Cardetail.class);
        return util.exportExcel(list, "cardetail");
    }

    /**
     * 获取cardetail详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:cardetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(cardetailService.findById(id));
    }

    /**
     * 新增cardetail
     */
    @PreAuthorize("@ss.hasPermi('business:cardetail:add')")
    @Log(title = "cardetail", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cardetail cardetail) {
        cardetailService.save(cardetail);
        return AjaxResult.success();
    }

    /**
     * 修改cardetail
     */
    @PreAuthorize("@ss.hasPermi('business:cardetail:edit')")
    @Log(title = "cardetail", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cardetail cardetail) {
        cardetailService.save(cardetail);
        return AjaxResult.success();
    }

    /**
     * 删除cardetail
     */
    @PreAuthorize("@ss.hasPermi('business:cardetail:remove')")
    @Log(title = "cardetail", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id) {
        cardetailService.deleteCardetailById(id);
        return AjaxResult.success();
    }
}
